list_merage = [2, 2, 4, 2]


def remove_zero_append_zero():
    for i in range(len(list_merage)):
        index = -(i + 1)
        # print(-(i + 1))
        if list_merage[index] == 0:
            del list_merage[index]
            list_merage.append(0)
    # print(list_merage)
    # 修改的可变变量 不用返回值
    return list_merage


demo_list = remove_zero_append_zero()


def merage_same_number_from_left_to_right(merage_list: list):
    for i in range(len(merage_list)):
        if i < len(merage_list) - 1:
            if merage_list[i] == merage_list[i + 1]:
                merage_list[i] = merage_list[i] + merage_list[i + 1]
                del merage_list[i + 1]
                merage_list.append(0)
    print(merage_list)


merage_same_number_from_left_to_right(demo_list)
